package com.shijiu.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.shijiu.annotation.RepeatSubmit;
import com.shijiu.pojo.Goods;
import com.shijiu.service.GoodsService;
import com.shijiu.common.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @Author xlj
 * @Date Created in  2023/4/21 17:10
 * @DESCRIPTION:
 * @Version V1.0
 */

@RestController
@RequestMapping("Goods")
@Transactional(rollbackFor = Exception.class)
public class GoodsController {
    @Resource
    private GoodsService goodsService;

    private static final Integer ID = 1;

    @ApiOperation("新增物料")
    @RepeatSubmit(interval = 2000, message = "接口请求过于频繁")
    @PostMapping("insertOrUpdate")
    public Result getOrderList(@RequestBody Goods goods){
        //admin  的id 未为 1
        if (goods == null) {
            return Result.fail(Integer.parseInt("505"),"参数为空");
        }
        return goodsService.saveOrUpdateById(goods);
    }
    @ApiOperation("删除物料")
    @RepeatSubmit(interval = 2000, message = "接口请求过于频繁")
    @PostMapping("deletedById")
    public Result deletedById(@RequestBody Goods goods){
        //admin  的id 未为 1
        String goodsId = goods.getId();
        if (StrUtil.isBlank(goodsId)) {
            return Result.fail(Integer.parseInt("505"),"物料id不能为空");
        }
        return goodsService.deletedById(goodsId);
    }
    @ApiOperation("上下架商品")
    @RepeatSubmit(interval = 2000, message = "接口请求过于频繁")
    @PostMapping("shelfById")
    public Result shelfById(@RequestBody Goods goods){
        //admin  的id 未为 1
        String goodsId = goods.getId();
        if (StrUtil.isBlank(goodsId)) {
            return Result.fail(Integer.parseInt("505"),"物料id不能为空");
        }
        return goodsService.shelfById(goodsId);
    }

    @ApiOperation("物料详情列表-分页-条件查询")
    @PostMapping("messageByPage")
    public Result messageByPage(@RequestBody Map<String, Object> requestBodyMaps){
        return goodsService.selectOrderListByPage(requestBodyMaps);
    }
}
